import java.awt.Graphics;
import java.util.HashMap;
import java.util.Set;

import javax.naming.spi.DirStateFactory.Result;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.RepaintManager;


public class ResultFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private final static int heigh = 400;
	private final static int width = 400;
	
	public ResultFrame(FuzzyNumber fn1, FuzzyNumber fn2, FuzzyNumber result){
        this.setSize(heigh, width);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setContentPane(new ResultPanel(fn1, fn2, result));
        this.setVisible(true);
	}

	
	private class ResultPanel extends JPanel{

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		
		FuzzyNumber fn1;
		FuzzyNumber fn2;
		FuzzyNumber result;
		
		public ResultPanel(FuzzyNumber fn1, FuzzyNumber fn2, FuzzyNumber result){
			this.fn1 = fn1;
			this.fn2 = fn2;
			this.result = result;
		}
		
		public void paintComponent(Graphics g){
			printFuzzy(fn1, g);
		}
		
		public void printFuzzy(FuzzyNumber fn, Graphics g){
			HashMap<Double, GeneralSegment> alphaCuts = fn.getAlphacuts();
			Set<Double> alphas = alphaCuts.keySet();
			
			for(double alpha : alphas){
				GeneralSegment gs = alphaCuts.get(alpha);
				//System.out.println(gs.size());
				int y = heigh-(int)(alpha/Calculator.resolution)*10-100;
				for(Segment segment : gs){
					int x1 = (int)(15*segment.getP1().getX()+200);
					int x2 = (int)(15*segment.getP2().getX()+200);
					g.drawLine(x1, y, x2, y);
					//g.fillOval(x1 , y, 4, 4);
					//g.fillOval(x2, y, 4, 4);
				}
			}
		}
		
	}
}